<template>
	<view>
		<nav-bar   fontColor="#FFFFFF" title="未付款采购订单">
			<!-- <view slot="right" @click="search">
				<text style="margin-right: 20rpx;font-weight: bold;">查询</text>
			</view> -->
		</nav-bar>
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<view>
			<view class="orderNumber">数量：{{total}}个</view>
			<mescroll-body @init="mescrollInit" @down="downCallback" @up="getDataList">
				<view v-for="(item,index) in dataList">
					<uni-list>
						<view style="padding: 20rpx;">
							<evan-checkbox-group @change="changeData" v-model="checkData">
								<evan-checkbox :key="item.id" :label="item.id"></evan-checkbox>
								<uni-list-item :index="index+1"
									:title="'公司名称:'+item.customerName + '\n物品名称:'+item.materialName"
									:note="'数量:'+item.qty + '\n'+ '日期:'+item.requstRecptDate" link="reLaunch" clickable>
								</uni-list-item>
							</evan-checkbox-group>
						</view>
					</uni-list>
				</view>
			</mescroll-body>
			<view style="height: 60rpx;">
				<view class="bottomBox">
					<view class="buttonBox">
						<button class="button_fix" :disabled="checkData[0] == null" @click="applyPaid" size="default">申请采易融付款</button>
					</view>
				</view>
			</view>
		</view>
		<!-- 上架弹窗 -->
		<uni-popup ref="unpaidOrder" type="dialog">
			<uni-popup-dialog ref="unpaidOrder" mode="unpaidOrder" title="申请采易融付款"
				@confirm="applyUnpaidConfirm"></uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
		</uni-popup>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog :before-close="true" type="info" cancelText="回到首页" confirmText="继续绑卡" title="提示"
				content="还有其他物品需要继续绑卡吗？" @confirm="dialogConfirm()" @close="dialogClose()"></uni-popup-dialog>
		</uni-popup>
		<!-- 	<uni-popup ref="popup" @change="change">
			<view class="popup">
				<image src="../../static/img/status.png" mode=""></image>
				<view>请扫描RFID射频标签</view>
			</view>
		</uni-popup> -->
		</view>
</template>

<script>
	var main = null;
	var receiver = null;
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	import uniList from '@/components/uni-list/uni-list.vue';
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		components: {
			uniList,
		},
		data() {
			return {
				msgType: 'success',
				messageText: '这是一条成功提示',
				qrCode: '',
				locationNo: '',
				number: '',
				orderNumber: "BC010302",
				//搜索内容
				checkData: [],
				dataList: [],
				total: null,
				rfid: '',
				itemId: [], //存放每个案件id的数组
				status: true,
				rfidLength: 0,
				epc: ''
			};
		},
		onLoad() {
			// this.startCheck();
			// this.getDataList();
			// this.get_gb();
			// uni.showLoading({
			// 	title: '加载中'
			// });
		},
		onShow() {
			
		},
		//方法
		methods: {
			applyUnpaidConfirm(){
				this.checkData = [];
				this.messageToggle('success','申请已提交，待审核')
			},
			applyPaid(){
				if(this.checkData[0] == null){
					this.messageToggle('error', '请选择内容进行分配')
				}
				else{
					this.$refs.unpaidOrder.open();
				}
			},
			getDataList(page) {
				let opt = {
					url: 'web/tWmsReciptIntoLocPlan/search/' + page.num + '/10',
					method: 'POST'
				};
				let params = {
					status: "proved",
					// jobType:"recept",
					// id: uni.getStorageSync('userInfo').id
				};
				this.$http.httpTokenRequest(opt, params).then(res => {
					if (res.data.code == 200) {
						// this.mescroll.endSuccess(res.data.data.records.length)
						this.mescroll.endByPage(res.data.data.records.length, res.data.data
						.total); //必传参数(当前页的数据个数, 总页数)
						// this.mescroll.endSuccess(res.data.data.records.length);
						this.total = res.data.data.total
						if (page.num == 1) {
							this.dataList = res.data.data.records;
						} else {
							this.dataList = this.dataList.concat(res.data.data.records);
						}
						if (res.data.data.records == '') {
							this.messageToggle('error', '暂无数据')
						}
						uni.hideLoading()
					} else {
						uni.hideLoading()
						this.messageToggle('error', res.data.msg)
					}

				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			handAllotConfirm(val){
				console.log(val)
			},
			dialogInputConfirm(val){
				console.log(val)
				let putawayLocationNo = '';
				for(let i in this.dataList){//查询locationNo是否一致
					if(this.dataList[i].id == this.checkData[0]){
						putawayLocationNo = this.dataList[i].locationNo
					}
				};
				console.log(putawayLocationNo)
				if(putawayLocationNo == val){
					uni.showLoading({
						mask:true,
						title:'加载中...'
					});
					let opt = {
						url:'web/tWmsReciptIntoLocPlan/putInLoc/' + this.checkData,
						method:'POST'
					};
					let params = {
						ids: this.checkData,
						locationNo: val
					};
					this.$http.httpTokenRequest(opt,params).then(res => {
						if(res.data.code == 200){
							this.messageToggle('success',res.data.msg)
							this.mescroll.resetUpScroll();
							uni.hideLoading();
						}
						else{
							this.messageToggle('error',res.data.msg)
							uni.hideLoading();
						}
					})
				}
				else{
					this.messageToggle('error','请重新找到库位并扫描')
				}
			},
			search() {
				uni.navigateTo({
					url: '/pages/order-pick/search'
				})
			},
			nextStep() {
				if(this.checkData[0] == null){
					this.messageToggle('error', '请选择内容')
				}
				else{
					this.$refs.inputDialog.open();
					
				}
			},
			changeData(r) {
				console.log(r)
			},
			// goQrCode() {
			// 	var that = this;
			// 	uni.scanCode({
			// 		success: function(res) {
			// 			console.log('条码类型：' + res.scanType);
			// 			console.log('条码内容：' + res.result);
			// 			let code1 = res.result.slice(0, 2)
			// 			let code2 = res.result.slice(2, 4)
			// 			let code3 = res.result.slice(4, 6)
			// 			let code4 = res.result.slice(6, 8)
			// 			that.qrCode = code1 + '-' + code2 + '-' + code3 + '-' + code4
			// 		}
			// 	});
			// },
			messageToggle(type, msg) {
				this.msgType = type
				this.messageText = msg
				this.$refs.message.open();
			},
			// get_gb() {
			// 	var that = this;
			// 	main = plus.android.runtimeMainActivity();
			// 	receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
			// 		onReceive: function(context, intent) {
			// 			plus.android.importClass(intent);
			// 			var data = intent.getExtra("data");
			// 			if (data) {
			// 				console.log(data)
			// 				that.rfid = data
			// 				that.rfidLength = 1;
			// 				// that.repeatRfid.push(data)
			// 				// for (let i = 0; i < that.repeatRfid.length; i++) {
			// 				// 	if (that.rfId.indexOf(that.repeatRfid[i]) == -1) {
			// 				// 		that.rfId.push(that.repeatRfid[i])
			// 				// 		console.log(that.rfId)
			// 				// 	}
			// 				// }
			// 			}
			// 		}
			// 	});
			// 	var IntentFilter = plus.android.importClass('android.content.IntentFilter');
			// 	let filter = new IntentFilter();
			// 	filter.addAction('android.rfid.epccode');
			// 	var info = main.registerReceiver(receiver, filter)
			// 	// main.unregisterReceiver(receiver)
			// },
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	page {
		background: #FFFFFF;
	}

	.popup {
		width: 100%;

		view {
			font-size: 35rpx;
			color: #FFFFFF;
			margin-top: 50rpx;
			text-align: center;
			letter-spacing: 3rpx;
			font-weight: 700;
		}

		image {
			display: block;
			margin: 0 auto;
		}
	}

	.end-title {
		display: flex;
		border-bottom: 1px solid #E5E5E5;
	}

	.end-title view {
		flex-grow: 1;
		text-align: center;
		background: #FFFFFF;
		// border-top: 1px solid #E5E5E5;
	}

	.btna {

		border-bottom: 2px solid #007AFF;
		color: #007AFF;
	}

	.tab {
		padding: 30rpx;
		font-size: 35rpx;
	}

	.mapStyle {
		height: 1200rpx;
		width: 100%;
		margin-top: 10rpx;
	}

	/*说明*/
	.orderNumber {
		text-align: center;
		padding: 30rpx;
		font-size: 32rpx;
		letter-spacing: 3rpx;
		font-weight: 700;
		// font-family: '宋体';
		// font-weight: ;
	}

	.imgCode {
		position: relative;
		background: linear-gradient(#000000, #000000) left top,
			linear-gradient(#000000, #000000) left top,
			linear-gradient(#000000, #000000) right top,
			linear-gradient(#000000, #000000) right top,
			linear-gradient(#000000, #000000) right bottom,
			linear-gradient(#000000, #000000) right bottom,
			linear-gradient(#000000, #000000) left bottom,
			linear-gradient(#000000, #000000) left bottom;
		background-repeat: no-repeat;
		background-size: 2px 20px, 20px 2px;
		height: 400rpx;
		width: 400rpx;
		margin: 0 auto;
		margin-top: 35%;
	}

	.txtTop {
		margin-top: 50rpx;
	}

	.qrImg {
		width: 250rpx;
		height: 250rpx;
		left: 20%;
		top: 15%;
	}

	.qrTitle {
		font-size: 28rpx;
		color: #3B5DE0;
		margin-top: 90rpx;
		text-align: center;
		letter-spacing: 3rpx;
	}


	
	.bottomBox{
		position: fixed;
		width: 100%;
		bottom: 0;
		margin-bottom: 20rpx;
		z-index: 1000;
	}
	.buttonBox {
		width: 100%;
		margin: 0 auto;
		display: flex;
		justify-content: space-around;
		
		// margin-top: 200rpx;
	}
	
	.button_fix {
		width: 90%;
		height: 70rpx;
		// margin: 0 auto;
		color: #FFFFFF;
		background: #2749C8;
		font-weight: bold;
		letter-spacing: 5rpx;
		font-size: 28rpx;
		line-height: 70rpx;
		
	}
</style>